package com.lkd.mapper;

import com.lkd.annotation.AutoFill;
import com.lkd.dto.RegionAllPageDto;
import com.lkd.entity.Node;
import com.lkd.vo.NodePageVo;
import com.lkd.vo.NodeVo;
import com.lkd.vo.RegionAllPageVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NodeMapper {

    //根据区域id查询该区域下的点位列表
    List<RegionAllPageVo> listByRid(RegionAllPageDto dto);
    //新增点位
    @AutoFill("insert")
    @Insert("insert into lkdremake.tb_node values (null,#{name},#{addr},#{areaCode},#{createUserId},#{regionId},#{businessId},#{ownerId},#{ownerName},#{updateTime},#{createTime})")
    Boolean save(Node node);
    //根据点位id查询该点位下的设备列表
    @Select("select * from lkdremake.tb_vending_machine where node_id=#{nodeId}")
    List<NodeVo> getVmList(Long nodeId);


    //修改点位
    @AutoFill("update")
    Boolean update(Node node);

    //删除点位
    @Delete("delete from lkdremake.tb_node where id=#{nodeId}")
    Boolean deleteById(Long nodeId);

    //查询设备数量，如果该点位下有设备 就不允许删除
    @Select("select count(*) from lkdremake.tb_vending_machine where node_id=#{nodeId}")
    int getVmCountByNodeId(Long nodeId);

    // 查询所有点位
    @Select("select * from lkdremake.tb_node where id=#{nodeId}")
    NodePageVo getByNodeId(Integer nodeId);

    // 查询点位总数
    @Select("select count(*) from lkdremake.tb_node")
    Integer count();
}
